package com.qf.shopgoods.config;

import com.qf.common.constant.RabbitMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    //创造一个交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(RabbitMqConstants.GOODS_EXCHANGE, true, false);
    }

    //创造一个队列
    @Bean
    public Queue queue() {
        return new Queue(RabbitMqConstants.GOODS_QUEUE_ES, true, false, false);
    }

    //绑定
    @Bean
    public Binding bindingBuilder() {
        return BindingBuilder.bind(queue()).to(fanoutExchange());
    }
}
